﻿CREATE PROCEDURE [dbo].[yaf_userforum_list](
                @UserID  INT  = NULL,
                @ForumID INT  = NULL)
AS
    BEGIN
        SELECT   a.*,
                 b.AccessMaskID,
                 b.Accepted,
                 Access = c.Name
        FROM     yaf_User a
                 JOIN yaf_UserForum b
                   ON b.UserID = a.UserID
                 JOIN yaf_AccessMask c
                   ON c.AccessMaskID = b.AccessMaskID
        WHERE    (@UserID IS NULL 
          OR a.UserID = @UserID)
        AND (@ForumID IS NULL 
              OR b.ForumID = @ForumID)
        ORDER BY a.Name
    END


